<template>
    <div class="home">
        <!--配送员界面-->
        <template v-if="isAdmin">
            <top-timer :back="false"/>
            <p class="curr_user_text font_40">当前登录用户: <span class="font_34 col_333">{{deliveryPhone=='undefined'?'——':deliveryPhone}}</span></p>
            <div class="flex center cabinet">
                <div class="wait_box flex1">
                    <div class="wait col_fff font_40 font_M">
                        {{waitNum}}
                    </div>
                    <p class="font_40 col_333 font_M">待收衣</p>
                </div>
                <div class="sub_box" v-for="(box,boxIndex) in boxDetailList" :key="boxIndex">
                    <div class="col_fff font_30 font_M" :class="box.boxType==='04'?'orange':box.boxType==='01'?'green':box.boxType==='03'?'blue':'purple'">
                        {{box.occupyBoxs}}/{{box.totalBoxs}}
                    </div>
                    <p class="font_40 col_666">{{box.boxTypeName}}</p>
                </div>
            </div>
            <div class="flex btns font_M font_40 col_444">
                <div class="flex1 btn flex align_center" @click="collectClothes">
                    <img src="@/assets/img/basket_icon2.png" alt="" style="width:1.44rem;height:1.44rem;">
                    <p>收衣</p>
                </div>
                <div class="flex1 btn btn flex align_center" @click="$router.push('deliveryCupboard')">
                    <img src="@/assets/img/car_icon.png" alt="" style="width:1.44rem;height:1.44rem;">
                    <p>投递</p>
                </div>
                <div class="flex1 btn btn flex align_center" @click="cleanBox">
                    <img src="@/assets/img/bucket_icon.png" alt="" style="width:1.44rem;height:1.44rem;">
                    <p>清理衣柜</p>
                </div>
            </div>
        </template>
        <!--用户界面-->
        <template v-else>
            <top-timer :back="false" :beginTimer="false"/>
            <div class="flex main_btns col_444 font_M font_40 center">
                <div class="flex1" @click="$router.push('QrCodeLogin')">
                    <img src="@/assets/img/xy_icon.png" alt="">
                    <span class="middle">洗衣</span>
                </div>
                <div class="flex1" @click="$router.push('QrCodeTake')">
                    <img class="middle" src="@/assets/img/basket_icon.png" alt="">
                    <span class="middle">取衣</span>
                </div>
            </div>
            <div class="flex sub_btns center font_36 col_666">
                <div class="flex1">
                    <div class="img_box explain" @click="guide()">
                        <img src="@/assets/img/book_icon.png" alt="">
                    </div>
                    <p>用户指南</p>
                </div>
                <div class="flex1" @click="$router.push('PriceList')">
                    <div class="img_box price_list">
                        <img src="@/assets/img/text_icon.png" alt="">
                    </div>
                    <p>价目表</p>
                </div>
                <!--<div class="flex1"  @click="testOpen()">-->
                    <!--<div class="img_box back_argin">-->
                        <!--<img src="@/assets/img/fx_icon.png" alt="">-->
                    <!--</div>-->
                    <!--<p>返洗</p>-->
                <!--</div>-->
                <div class="flex1">
                    <div class="img_box get_home_service">
                        <img src="@/assets/img/user_icon.png" width="50" height="50" alt="">
                    </div>
                    <p>上门服务</p>
                </div>
            </div>
        </template>
        <footer>
            <div class="pos_rel">
                <div class="tran overflow col_blue font_36" :class="clicked?'act_tran':''">
                    <div class="img_box" @click="clicked = !clicked">
                        <img src="@/assets/img/admin_head.png" width="22" height="22" alt="">
                    </div>
                    <span @click="deliveryLogin">{{!isAdmin?'配送员登录':'退出登录'}}</span>
                </div>
                <div class="code_box center col_999" v-show="!isAdmin">
                    <img src="@/assets/img/mini.png" alt="">
                    <p class="center">微信扫码</p>
                    <p>进入小程序</p>
                </div>
            </div>
        </footer>
        <!--<div class="test_btn col_blue font_36" v-if="isAdmin" @click="testOpenBox()">-->
            <!--测试-->
        <!--</div>-->
        <div class="code font_28 col_999" v-if="isAdmin">{{versionCode}}</div>
        <top-tips/>  <!--开箱:second=240-->
    </div>
</template>

<script>
  export default {
    name: 'home',
    data() {
      return {
        clicked: false,
        isAdmin: this.$route.query.isAdmin,
        cabinetCode:localStorage.getItem("cabinetCode"),
        address:localStorage.getItem("address"),
        boxDetailList:[],
        waitNum:0,
        versionCode:localStorage.getItem('versionCode'),
        deliveryPhone:localStorage.getItem('deliveryPhone'),
    }
    },
    created() {
      let token = localStorage.getItem('token')
      document.addEventListener('deviceready', this.onDeviceReady, false)
      if(token!=='undefined' && this.isAdmin) {
        this.getBoxDetailList()
        this.getCollectionclothes()
      }
    },
    methods:{
      onDeviceReady () {
        let updateUrl = `${this.$global.API}upload/apk/version.xml`;
        let versionCode = AppVersion.build
        localStorage.setItem('versionCode', versionCode);
        let token = localStorage.getItem('token')
        if (device.platform === 'Android' && token!=='undefined' && this.isAdmin) {
          window.AppUpdate.checkAppUpdate(()=>{
          }, (err)=>{

          }, updateUrl)
        }
      },
      getBoxDetailList() {
        this.waitNum = 0
        this.$axios.get('receiveClothesRest/getBoxDetailList',{
          params:{
            cabinetId:localStorage.getItem('cabinetId')
          }}).then(res => {
            this.boxDetailList = res.data
        })
      },
      getCollectionclothes() {
        this.$axios.get('receiveClothesRest/getCollectionclothes'
            // ,{
            //     params:{
            //         cabinetId:localStorage.getItem('cabinetId')
            //     }
            // }
        ).then(res => {
            this.waitNum = res.data
        })
      },
      deliveryLogin() {
        if(!this.isAdmin){//管理员登录
          this.$router.push({path:'deliveryLogin'})
        } else {
          this.isAdmin = false//管理员退出
          localStorage.removeItem('token');
        }
      },
      // 收衣
      collectClothes() {
        this.$router.push({path:'collectClothes'})
      },
      // 清理衣柜
      cleanBox() {
        this.$router.push({path:'cleanBox'})
      },
      testCmd(){
        alert('开始测试2');
        let success =(res)=>{
          alert("测试结果"+res);
        }
        let error =(res)=>{
          alert("测试失败"+res);
        }
        window.cordova.plugins.CabinetPlugin.sendQueryCommand([1,1], success, error)
      },
      testOpen(){
        alert('开始开箱2');
        let success =(res)=>{
          alert("开箱结果"+res);
        }
        let error =(res)=>{
          alert("开箱失败"+res);
        }
        window.cordova.plugins.CabinetPlugin.sendOpenBoxCommand([1,1], success,error)
      },
      testOpenBox(){
        this.$router.push({path:'TestOpenCupboard'})
      },
      guide(){
        this.$router.push('guide')
      }
    }
  };
</script>
<style lang="scss">
    .home {
        background-color: #F9FCFF!important;
        .main_btns {
            padding: 0.80rem 0.64rem;
            .flex1:first-of-type {
                margin-right: 0.32rem;
            }
            .flex1 {
                background-color: white;
                line-height: 2.40rem;
                height: 2.40rem;
                border-radius: 0.32rem;
                box-shadow: 0.04rem 0.04rem 0.20rem 0 rgba(0, 0, 0, 0.1);
                img {
                    margin-right: 0.35rem;
                    width:1.44rem;
                    height:1.44rem;
                }
            }
        }
        .sub_btns{
            padding: 0 0.60rem 0 1.20rem;
            .flex1 {
                margin-right: 0.64rem;
                text-align: center;
                img {
                    vertical-align: middle;
                    width:1rem;
                    height:1rem;
                }
                p {
                    line-height: 1.2;
                }
            }
            .img_box {
                display: inline-block;
                width:1.60rem;
                height:1.60rem;
                line-height: 1.60rem;
                box-shadow:0.04rem 0.04rem 0.20rem 0rem rgba(0,0,0,0.1);
                border-radius: 45%;
                margin-bottom: 0.20rem;
            }
            .explain {
                background:linear-gradient(156deg,rgba(255,185,105,1) 0%,rgba(255,119,6,1) 100%);
            }
            .price_list {
                background:linear-gradient(156deg,rgba(32,234,158,1) 0%,rgba(29,192,145,1) 100%);
            }
            .back_argin {
                background:linear-gradient(156deg,rgba(121,201,255,1) 0%,rgba(30,132,219,1) 100%);
            }
            .get_home_service {
                background:linear-gradient(156deg,rgba(167,161,255,1) 0%,rgba(97,109,252,1) 100%);
            }
        }
        footer {
            position: absolute;
            bottom: 1.5rem;
            left: 0;
            right: 0;
            .tran {
                line-height: 0.80rem;
                height: 0.80rem;
                width: 3.12rem;
                background-color: #D8EBFF;
                border-radius: 0 2.00rem 2.00rem 0;
                display: inline-block;
                transform: translate3D(-2.10rem,0,0);
                transition: .5s;
                .img_box {
                    background-color: #D8EBFF;
                    display: inline-block;
                    transition: .5s;
                    transform: translate3D(2.10rem,0,0);
                    padding: 0 0 0 0.30rem;
                    img {
                        vertical-align: sub;
                        width:0.44rem;
                        height:0.44rem;
                    }
                }
                span {
                    margin-left: 0.20rem;
                }
            }
            .act_tran {
                transform: translate3D(0rem,0,0);
                .img_box {
                    transform: translate3D(0,0,0);
                }
            }
            .code_box {
                font-size: 0.20rem;
                position: absolute;
                right: 0.4rem;
                bottom: 0;
                width:1.8rem;
                height:2.39rem;
                background:rgba(255,255,255,1);
                box-shadow:0px 0px 0.1rem 0px rgba(10,130,236,0.2);
                border-radius:0.16rem;
                border:2px solid rgba(10,130,236,1);
                /*border:0.02rem solid rgba(10,130,236,1);*/
                img {
                    margin: 0.10rem 0.10rem 0.05rem;
                    width:1.6rem;
                    height:1.6rem;
                }
                p {
                    line-height: 0.3rem;
                }
            }
        }
        .test_btn{
            line-height: 0.80rem;
            height: 0.80rem;
            width:1.6rem;
            background-color: #D8EBFF;
            border-radius:2.00rem 0  0 2.00rem;
            text-align: center;
            position: fixed;
            right:0;
            bottom:1.5rem;
        }
        .curr_user_text {
            color: #999999;
            margin: 0.50rem 0 0.40rem 0.64rem;
        }
        .cabinet{
            padding: 0 0.64rem 0.80rem;
            align-items: flex-end;
            p {
                line-height: 1.2;
            }
            .wait_box {
                margin-right: 1.12rem;
                .wait{
                    margin-bottom: 0.20rem;
                    width:1.20rem;
                    height:1.20rem;
                    line-height:1.20rem;
                    background:linear-gradient(135deg,rgba(255,129,151,1) 0%,rgba(214,30,13,1) 100%);
                    box-shadow:0.04rem 0.04rem 0.20rem 0rem rgba(0,0,0,0.2);
                    border-radius:0.60rem;
                }
                p {
                    width:1.20rem;
                }
            }
            .sub_box {
                margin-left: 0.80rem;
                >div {
                    margin:0 auto 0.20rem;
                    width:1.00rem;
                    height:1.00rem;
                    line-height:1.00rem;
                    box-shadow:0.04rem 0.04rem 0.20rem 0rem rgba(0,0,0,0.2);
                    border-radius:0.60rem;
                }
                .orange {
                    background:linear-gradient(135deg,rgba(255,185,105,1) 0%,rgba(255,119,6,1) 100%);
                }
                .green {
                    background:linear-gradient(135deg,rgba(32,234,158,1) 0%,rgba(29,192,145,1) 100%);
                }
                .blue {
                    background:linear-gradient(135deg,rgba(121,201,255,1) 0%,rgba(30,132,219,1) 100%);
                }
                .purple {
                    background:linear-gradient(135deg,rgba(167,161,255,1) 0%,rgba(97,109,252,1) 100%);
                }
            }
        }
        .btns {
            padding: 0 0.64rem;
            flex-wrap:wrap;
            justify-content: space-between;
            .btn {
                flex: 0 0 3.00rem;
                height:3.60rem;
                background:rgba(255,255,255,1);
                box-shadow:0.04rem 0.04rem 0.20rem 0rem rgba(0,0,0,0.1);
                border-radius:0.32rem;
                flex-direction: column;
                justify-content: center;
                img {
                    margin-bottom: 0.20rem;
                }
            }
        }
        .code{
            padding:0.2rem 0.3rem;
            position: fixed;
            right:0;
            bottom:1rem;
        }
    }
</style>
